package com.example.scott.myapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayList<Mammal> a = new ArrayList<Mammal>();
        for(int i = 0; i<14; i++)
        {
           switch (i%3)
           {
               case 0:
                   a.add(new Mammal(i*3,i*40));
                   break;
               case 1:
                   a.add(new Dog(i*3,i*40));
                   break;
               case 2:
                   a.add(new Chimp(i*3,i*40));
                   break;

           }
        }
        ((Dog)a.get(1)).bark();
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CalculateOutPut();
            }
        });
    }

    private void CalculateOutPut() {
        String s =  ((TextView)findViewById(R.id.editText)).getText().toString();
        int i = Integer.parseInt(((TextView) findViewById(R.id.editText2)).getText().toString());
        float h = Float.parseFloat(((TextView) findViewById(R.id.editText3)).getText().toString());
                float w = Float.parseFloat(((TextView) findViewById(R.id.editText4)).getText().toString());
        float BMI = w/h/h*10000;
        String message = "";
        if((i<50&&BMI>=18&&BMI<25)||(i>=50&&BMI>22&&BMI<26))
            message = "You are in good Condition";
        else
            message = "You are not in good condition";
        ((TextView)findViewById(R.id.textView6)).setText("HI There "+s+"\nYour BMI ="+ BMI+"\n"+message);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
